package com.thoughtworks.collection;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.*;

public class Flaten {

    Integer[][] array;
    public Flaten(Integer[][] array) {
        this.array = array;
    }

    public List<Integer> transformToOneDimesional() {

        int len = 0;
        int index = 0;
        for (Integer[] element : array) {
            len += element.length;
        }
        Integer[] sz = new Integer[len];
        for (Integer[] integers : array) {
            for (Integer integer : integers) {
                sz[index++] = integer;
            }
        }
        List<Integer> list = Arrays.asList(sz);
        return list;
    }

    public List<Integer> transformToUnrepeatedOneDimesional() {
        int len = 0;
        int index = 0;
        for (Integer[] element : array) {
            len += element.length;
        }
        Integer[] sz = new Integer[len];
        for (Integer[] integers : array) {
            for (Integer integer : integers) {
                sz[index++] = integer;
            }
        }
        List<Integer> list = Arrays.asList(sz);
        LinkedHashSet<Integer> hashSet = new LinkedHashSet<>(list);
        List<Integer> list2 =new ArrayList<>();
        list2.addAll(hashSet);
        return list2;
    }
}
